import { main, module } from "./package.json";
import cjs from "rollup-plugin-commonjs";
import babel from "rollup-plugin-babel";
import resolve from "rollup-plugin-node-resolve";
import path from "path";
import { uglify } from "rollup-plugin-uglify";
import { terser } from "rollup-plugin-terser";

const commonPlugins = [
  babel({
    runtimeHelpers: true
  }),
  resolve(),
  cjs({
    include: "./node_modules/**",
    namedExports: {
      "./node_modules/react/index.js": [
        "Component",
        "PureComponent",
        "Children",
        "createElement"
      ],
      "./node_modules/react-dom/index.js": ["render"],
      "./node_modules/redux/es/redux.js": [
        "combineReducers",
        "createStore",
        "applyMiddleware"
      ],
      "./node_modules/react-redux/es/index.js": ["Provider", "connect"],
      "./node_modules/react-is/index.js": ["isValidElementType"]
    }
  })
];

const cjsPlugins = [].concat(commonPlugins, [uglify()]);
const esPlugins = [].concat(commonPlugins, [terser()]);

export default [
  {
    input: path.resolve(__dirname, "src", "index.js"),
    output: {
      file: main,
      format: "cjs"
    },
    plugins: cjsPlugins
  },
  {
    input: path.resolve(__dirname, "src", "index.js"),
    output: {
      file: module,
      format: "es"
    },
    plugins: esPlugins
  }
];
